﻿namespace DeltaGroup.WheelOfJeopardy.UI.Commands
{
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;

    public abstract class LoadUserControlCommand : RoutedCommand
    {
        #region Methods

        /// <summary>
        /// Determines whether this instance can execute the specified sender.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Windows.Input.CanExecuteRoutedEventArgs"/> instance containing the event data.</param>
        public virtual void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        /// <summary>
        /// Loads the specified window.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="executedRoutedEventArgs">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        public abstract void Load(Window window, ExecutedRoutedEventArgs executedRoutedEventArgs);

        #endregion Methods
    }

    public class LoadUserControlCommand<T> : LoadUserControlCommand
        where T : UserControl, new()
    {
        #region Properties

        /// <summary>
        /// Gets or sets the user control instance.
        /// </summary>
        /// <value>The user control instance.</value>
        public T UserControlInstance
        {
            get; private set;
        }

        #endregion Properties

        #region Methods

        /// <summary>
        /// Loads the specified window.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="executedRoutedEventArgs">The <see cref="System.Windows.Input.ExecutedRoutedEventArgs"/> instance containing the event data.</param>
        public override void Load(Window window, ExecutedRoutedEventArgs executedRoutedEventArgs)
        {
            window.Content = (UserControlInstance = new T());
        }

        #endregion Methods
    }
}